package gui;

import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import simuAnnealing.Solution;

/**
 * 
 * @author edilson
 */
@SuppressWarnings("serial")
public class SimulatedPlot extends javax.swing.JPanel {

	Solution solution;
	ArrayList<Double> chosenArr = new ArrayList<Double>();
	
	public SimulatedPlot(Solution solution, GraphPlotMode method) {
		this.solution = solution;
		initComponents();
		if(method == GraphPlotMode.BY_FINAL_SOLUTIONS){
			chosenArr = this.solution.getSimulatedAnnealingAlg().getMidWayFinalSolution();
		}
		else
		{
			chosenArr = this.solution.getSimulatedAnnealingAlg().getMidWayActualSolution();
		}
		createPlot();
	}

	private void createPlot() {

		XYSeries series = new XYSeries("Series");
		Iterator<Double> iterator = chosenArr.iterator();
		for (int i = 0; i < chosenArr.size(); i++) {
			series.add(i, iterator.next());
		}

		XYSeriesCollection seriesCollection = new XYSeriesCollection();
		seriesCollection.addSeries(series);

		JFreeChart chart = ChartFactory.createXYLineChart(
				"The power cost as a function of state (Solution number)",
				"State (Solution number)", "Power cost", seriesCollection,
				PlotOrientation.VERTICAL, false, false, true);

		ChartPanel panel = new ChartPanel(chart);
		panel.setMouseZoomable(true);
		this.add(panel);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {
	}// </editor-fold>//GEN-END:initComponents
		// Variables declaration - do not modify//GEN-BEGIN:variables
		// End of variables declaration//GEN-END:variables
}
